home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cpptut22 / newdel.cpp < prev    next >
C/C++ Source or Header  |  1992-01-19  |  1KB  |  61 lines

  1.                                     // Chapter 3 - Program 2
  2. #include <iostream.h>
  3.  
  4. struct date {
  5.    int month;
  6.    int day;
  7.    int year;
  8. };
  9.  
  10. main()
  11. {
  12. int index, *point1, *point2;
  13.  
  14.    point1 = &index;
  15.    *point1 = 77;
  16.    point2 = new int;
  17.    *point2 = 173;
  18.    cout << "The values are " << index << "  " << 
  19.                                   *point1 << "  " << *point2 << "\n";
  20.    point1 = new int;
  21.    point2 = point1;
  22.    *point1 = 999;
  23.    cout << "The values are " << index << "  " << 
  24.                                   *point1 << "  " << *point2 << "\n";
  25.    delete point1;
  26.  
  27. float *float_point1, *float_point2 = new float;
  28.  
  29.    float_point1 = new float;
  30.    *float_point2 = 3.14159;
  31.    *float_point1 = 2.4 * (*float_point2);
  32.    delete float_point2;
  33.    delete float_point1;
  34.  
  35. date *date_point;
  36.  
  37.    date_point = new date;
  38.    date_point->month = 10;
  39.    date_point->day = 18;
  40.    date_point->year = 1938;
  41.    cout << date_point->month << "/" << date_point->day << "/" <<
  42.                                             date_point->year << "\n";
  43.    delete date_point;
  44.  
  45. char *c_point;
  46.  
  47.    c_point = new char[37];
  48.    delete c_point;
  49.    c_point = new char[sizeof(date) + 133];
  50.    delete c_point;
  51. }
  52.  
  53.  
  54.  
  55.  
  56. // Result of execution
  57. //
  58. // The values are 77  77  173
  59. // The values are 77  999  999
  60. // 10/18/1938
  61.